
 class fu {
    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
     public int i=0;
     public TreeNode buildTree(int[] inorder, int[] postorder) {
         i=postorder.length-1;
         int begin=0;
         int end=inorder.length-1;
         return build(inorder,postorder,begin,end);


     }

     public TreeNode build(int[]inorder,int[]postorder,int begin,int end)
     {
         if(begin>end)
         {
             return null;
         }
         TreeNode head=new TreeNode(postorder[i]);
         int cur=find(postorder[i],inorder);

         i--;
         if(cur==-1)
         {
             return null;
         }
         // head.left=build(inorder,postorder,begin,cur-1);
         head.right=build(inorder,postorder,cur+1,end);
         head.left=build(inorder,postorder,begin,cur-1);
         return head;
     }
     public int find(int a,int[]inorder)
     {
         int c=0;
         for(c=0;c<inorder.length;c++)
         {
             if(c==a)
             {
                 return c;
             }
         }
         return -1;
     }



 }







public class text80 {
    public static void main(String[] args) {
        fu a=new fu();
        int[]inorder ={9,3,15,20,7};
        int[]postorder={9,15,7,20,3};
        a. buildTree(inorder,postorder);



    }
}
